;; Sri Ganeshji : Sri Balaji : Sri Pitreshwarji : Sri Durgaji : Sri Venkateshwara

/*
Objective(s) -
-	This code demonstrates the concept of Auto Column Reports using Trial Balance

Last modification -
-	Altered on 09-11-2009
*/

[Report: AutoCol Trial Balance]

;;	Title		: $$LocaleString:"Trial Balance"
	Form		: AutoCol Trial Balance

	Repeat      : SVCurrentCompany, SVFromDate, SVToDate
	ColumnReport: MyMultiColumns1

	Variable	: AutoCol TB Group, IsLedgerWise, SVPeriodicity

    PrintSet    : Report Title      : $$LocaleString:"Trial Balance"
    Set         : IsLedgerWise      : No

;; When the attribute Column Report is mentioned, the attribute 
;; Repeat should also be mentioned. The New Column, Alter Column and 
;; Delete Column buttons will automatically get activated 
;; once Column Report & Repeat attributes are mentioned 
;; together in the report.

;; PrintSet At Report Definition will set the Variable Value
;; in Print Mode

[Form: AutoCol Trial Balance]
    
    Button      : F2ChangePeriod, ChangeCompany, LedgerWiseButton
	Keys        : ChangePeriod
	
;;To incorporate the change in TallyPrime
	Bottom Button	: Add Column, Alter Column, Delete Column

	BottomButton: MyAutoButton, BlankButton, InvReports, AcctReports, ReportOperations, FilterButton, ValueButton
	Buttons		: PrintButton, ExportButton, UploadButton, MailButton
	Parts		: AutoCol TB Title, AutoCol TB Details
	Page Break  : DSP ClPageBreak, AutoCol TB OpPgPart
	Height		: 100% Page
	Width		: 100% Page
	Space Top	: 0
	Space Left	: 0
	Background	: Released Pale Yellow
	Option		: Prn AutoCol TB	: $$InPrintMode
	
	[!Form: Prn AutoCol TB]
	
        Add         : Parts     : At Beginning  : DSP CompanyName, DSP CompanyAddress, DSP ReportTitle
   		Space Left	: 0.25 inch
   		
;; For enabling Titles during Printing, Form Level Optional parts 
;; Company Name, Address and Report Title are used from defTDL.
       
    [Part: AutoCol TB OpPgPart]
    
        Parts       : DSP CompanyName, DSP CompanyAddress, DSP ReportTitle, AutoCol TB Title
        Vertical    : Yes

;; Every continuous page should have the above parts during Printing

	[Part: AutoCol TB Title]

		Lines		: AutoCol TB Title1, AutoCol TB Title2, AutoCol TB Title3, AutoCol TB STitle
		Border      : Thin Top

		[Line: AutoCol TB Title1]

			Use			: AutoCol TB Title3
			Local		: Field		: Name Field		    : Set as		: ""
			Local		: Field		: AutoCol TB DrAmt Field	: Set as		: @@CmpMailName
			Local		: Field		: AutoCol TB DrAmt Field	: Lines			: 0
			Local		: Field		: AutoCol TB DrAmt Field	: Border		: Thin Left
			Invisible   : $$IsCommon:SVCurrentCompany AND $$InPrintMode
			
;; This Line is made Invisible in Print Mode only if Columns selected
;; are of single company

		[Line: AutoCol TB Title2]

			Use			: AutoCol TB Title3
			Local		: Field		: Default		    	: Style			: Normal
			Local		: Field		: Name Field		    : Set as		: $$LocaleString:"Particulars"
			Local		: Field		: Name Field		    : Style			: Normal Bold
			Local		: Field		: Name Field	    	: WideSpaced	: Yes
			Local		: Field		: AutoCol TB DrAmt Field	: Set as		: @@DSPDateStr
			Local		: Field		: AutoCol TB DrAmt Field	: Border		: Left Full Thin Bottom
			
;; DSPFDateStr is the Default Formula which displays the values 
;; present in both the date variables - SVFromDate & SVTodate 

		[Line: AutoCol TB Title3]

			Fields		: Name Field, AutoCol TB DrAmt Field
			Local		: Field		: Default			    : Type			: String
			Local		: Field		: Name Field		    : Set as		: ""
			Local		: Field		: Name Field		    : Align			: Center
			Local		: Field		: AutoCol TB DrAmt Field	: Align			: Centre
			Local		: Field		: AutoCol TB DrAmt Field	: Border		: Left Full Thin Bottom
			Local		: Field		: AutoCol TB DrAmt Field	: Set as		: $$LocaleString:"Closing Balance"
			Repeat		: AutoCol TB DrAmt Field

		[Line: AutoCol TB STitle]

			Fields		: Name Field, AutoCol TB Amount Field
			Local		: Field		: Default			    : Style			: Normal
			Local		: Field		: Default			    : Align			: Centre
			Local		: Field		: Default			    : Type			: String
			Local		: Field		: Name Field		    : Set as		: ""
			Local		: Field		: AutoCol TB DrAmt Field	: Set as		: $$LocaleString:"Debit"
			Local		: Field		: AutoCol TB CrAmt Field	: Set as		: $$LocaleString:"Credit"
			Local		: Field		: AutoCol TB CrAmt Field	: Border		: Thin Left
			Repeat		: AutoCol TB Amount Field
			Border		: Thin Bottom
			
	[Part: AutoCol TB Details]

		Lines		: AutoCol TB Details
		BottomLines	: AutoCol TB Total
		Repeat		: AutoCol TB Details	: AutoCol TB GroupLed
		Total		: AutoCol TB DrAmt Field, AutoCol TB CrAmt Field
		Scroll		: Vertical
		CommonBorder: Yes
		Float		: Yes
		Page Break  : AutoCol TB ClPgLine, AutoCol TB OpPgLine
		
        Option      : AutoCol TB Details Led : ##IsLedgerWise
        
;; Part Level Page Breaks is introduced to have Page Totals
;; at the beginning (except first page) and end (except last page)
;; of every page

;; The optional part is selected when Ledgerwise is selected by the user.
        
        [!Part: AutoCol TB Details Led]

		    Repeat		: AutoCol TB Details	: AutoCol TB Led
		    Local       : Collection: AutoCol TB Led         : BelongsTo     : Yes

;; If Ledgerwise Option is selected by the user, Collection should
;; have attribute BelongsTo set to Yes as the Ledgers pertaining to
;; all the Groups and Sub-Groups needs to be displayed together
		    
        [Line: AutoCol TB ClPgLine] ;; Line for Closing Page Totals
        
            Use         : AutoCol TB Details
            Delete      : Fields    : AutoCol TB Amount Field
            Add         : Fields    : AutoCol TB AmountSTField
            Delete      : Repeat    : AutoCol TB AmountSTField
            Add         : Repeat    : AutoCol TB AmountSTField

            Local       : Field     : Default               : Style         : Normal Bold
			Local		: Field		: AutoCol TB Name Field	: Set as		: "Carried Over"
			Local		: Field		: AutoCol TB Name Field	: WideSpaced    : Yes
			Local		: Field		: AutoCol TB DrAmtSTField: Set as		: $$Total:AutoColTBDrAmtField
			Local		: Field		: AutoCol TB DrAmtSTField: Border        : Totals
			Local		: Field		: AutoCol TB CrAmtSTField: Set as		: $$Total:AutoColTBCrAmtField
			Local		: Field		: AutoCol TB CrAmtSTField: Border        : Totals					    		
			Space Top   : 1

        [Line: AutoCol TB OpPgLine] ;; Line for Opening Page Totals
        
            Use         : AutoCol TB ClPgLine
			Local		: Field		: AutoCol TB DrAmtSTField: Delete        : Border
			Local		: Field		: AutoCol TB CrAmtSTField: Delete        : Border
			Local		: Field		: AutoCol TB Name Field	: Set as		: "Brought Foward"
			Space Top   : 0
			Space Bottom: 1
						
            [Field: AutoCol TB AmountSTField] ;; New Field Definition for the Page Totals
            
				Fields		: AutoCol TB DrAmt STField, AutoCol TB CrAmt STField
				Border		: Thin Left
				
                [Field: AutoCol TB DrAmtSTField]
                
                    Use         : AutoCol TB DrAmt Field

                [Field: AutoCol TB CrAmtSTField]
                
                    Use         : AutoCol TB CrAmt Field
                                    
		[Line: AutoCol TB Details]

			Fields		: AutoCol TB Name Field, AutoCol TB Amount Field
			Local		: Field		: AutoCol TB Name Field	: Set as		: $$Name
			Local		: Field		: AutoCol TB DrAmt Field	: Set as		: if $$IsDr:$ClosingBalance then $ClosingBalance else 0
			Local		: Field		: AutoCol TB CrAmt Field	: Set as		: if $$IsDr:$ClosingBalance then 0 else $ClosingBalance
			Repeat		: AutoCol TB Amount Field

;; Repeat Attribute of Line will position the Field to the Right, 
;; as if it is a Right Field.
	
			[Field: AutoCol TB Name Field]

				Use			: Name Field
				Variable	: AutoCol TB Group
				Display		: AutoCol Trial Balance		: $$IsGroup
				Option		: AutoCol TB LedName Field	: $$IsLedger

				[!Field: AutoCol TB LedName Field]

					Variable	: LedgerName
					Display		: Ledger Monthly Summary
					Style       : Normal Italic

			[Field: AutoCol TB Amount Field]

				Fields		: AutoCol TB DrAmt Field, AutoCol TB CrAmt Field
				Border		: Thin Left
				Display		: AutoCol Trial Balance		: $$IsGroup
				Display		: Ledger Monthly Summary    : $$IsLedger
			    			    
				[Field: AutoCol TB DrAmt Field]

					Use			: Amount Field
					Style       : Normal

				[Field: AutoCol TB CrAmt Field]

					Use			: Amount Field
					Style       : Normal

			[Collection: AutoCol TB GroupLed]
			
				Collection	: AutoCol TB Group, AutoCol TB Led
			
			[Collection: AutoCol TB Group]
			
				Type		: Group
				Child Of	: ##AutoColTBGroup
				Filter		: NoProfit
				Fetch		: Name, ClosingBalance
;; NoProfit Formula is used to Filter all the Ledgers
;; except Profit and Loss Account.
			
			[Collection: AutoCol TB Led]
			
				Type		: Ledger
				Child Of	: ##AutoColTBGroup
				Filter		: NoProfit

			[Variable: AutoCol TB Group]
			
				Type		: String
				Default     : ""
				Volatile	: Yes
;;	
;;			[System: Formula]
;;
;;				NoProfit	: NOT $$IsLedgerProfit AND $ClosingBalance > 0

;; Function IsLedgerProfit returns Yes, only if the current object
;; is a Profit & Loss Ledger Account.

    	[Line: AutoCol TB Total]

			Use			: AutoCol TB Details
			Local       : Field     : Default               : Style         : Normal Bold
			Local		: Field		: AutoCol TB Name Field	: Set as		: "GRAND TOTAL"
			Local       : Field     : AutoCol TB Name Field	: WideSpaced    : Yes
			Local		: Field		: AutoCol TB Name Field	: Align			: Centre
			Local		: Field		: AutoCol TB DrAmt Field	: Set as		: $$Total:AutoColTBDrAmtField
			Local		: Field		: AutoCol TB CrAmt Field	: Set as		: $$Total:AutoColTBCrAmtField
			Border		: Flush Totals
			Fixed		: Yes
			Space Top   : 1

;; Fixed Attribute at Line Definition will not allow the cursor to be
;; placed on that line while viewing and scrolling

;; End-of-Trial-Balance

;; Report for displaying Column Option

[Report: MyMultiColumns1]

    Title       : $$LocaleString:"Column Details"

[Form: MyMultiColumns1]

    No Confirm  : Yes
    Full Width  : No

    Space Right : 0.25
    Background  : @@SV_UNBLUE
    Parts       : My MultiColumns1
    Option      : Small Size Form

[Part: My MultiColumns1]

    Lines       : Form SubTitle, My MultiCompany, My MultiFromDate, My MultiToDate
    Local       : Field : Form SubTitle     : Info      : $$LocaleString:"Column Details"

;; Changes to achieve AutoColumn

[Button: MyAutoButton]

	Key         : Alt+N
    Action      : Auto Columns : MyAutoColumns1
    Title       : $$LocaleString:"Auto Column"
    Inactive    : $$NumItems:MyAutoColumns1 < 1

;; Action Auto Columns is an action which takes a report as its value
;; and gives auto columns in the base report accordingly.
;; MyAutoColumns is a report being displayed when the button
;; MyAutoButton is clicked. 

[Collection: MyAuto Columns1]

    Title       : $$LocaleString:"Column Details"
	Object		: MyCurrentCompany, MyQuarterly, MyMonthly, MyYearly, MyHalfYearly
	Filter		: Belongs
	Format      : $$Name, 15
	    Client Only : Yes

;; Belongs is a system formula which filters the objects
;; based on the value of the Methods BelongsIf of all the objects

;; Function Name returns the Name of any given objects

[Object: MyCurrentCompany]

    Name        : $$LocaleString:"Company"
    VarName     : "SVCurrentCompany"
    CollName    : "List of Primary Companies"
    BelongsIf   : $$NumItems:ListOfPrimaryCompanies > 1
    IsAgeWise   : No
    Periodicity : ""

;; Function NumItems returns the number of selected companies
;; BelongsIf is a method of object MyCurrentCompany, which
;; is used to control the display of the object in the collection

[Object: MyQuarterly]

    Name        : $$LocaleString:"Quarterly"
    VarName     : "SVFromDate, SVToDate"
    CollName    : "Period Collection"
    BelongsIf   : "Yes"
    IsAgeWise   : No
    Periodicity : "3 Month"

[Object: MyHalfYearly]

    Name        : $$LocaleString:"Half-Yearly"
    VarName     : "SVFromDate, SVToDate"
    CollName    : "Period Collection"
    BelongsIf   : "Yes"
    IsAgeWise   : No
    Periodicity : "6 Month"

[Object: MyMonthly]

    Name        : $$LocaleString:"Monthly"
    VarName     : "SVFromDate, SVToDate"    
    CollName    : "Period Collection"
    BelongsIf   : "Yes"
    IsAgeWise   : No
    Periodicity : "Month"

[Object: MyYearly]

    Name        : $$LocaleString:"Yearly"
    VarName     : "SVFromDate, SVToDate"    
    CollName    : "Period Collection"
    BelongsIf   : "Yes"
    IsAgeWise   : No
    Periodicity : "Year"

;; Report AutoColumn

[Report: MyAutoColumns1]

    Auto        : Yes
    Title       : $$LocaleString:"Auto Repeat Columns"

[Form: MyAutoColumns1]

    No Confirm  : Yes
    Full Width  : No

    Space Top   : 1
    Space Bottom: 1
    Space Left  : 1
    Space Right : 1

    Background  : @@SV_UNYELLOW
    Parts       : My AutoColumns
    Output      : My AutoColumns
    Option      : Small Size Form

;; Output Attribute at Form Definition is used to return a Field value  
;; to the calling Report

;; No Confirm Attribute at Form Definition will not prompt the user to 
;; save the auto-column screen

[Part: My AutoColumns]

    Lines       : Form SubTitle, My AutoColumns
    Local       : Field : Form SubTitle         : Info      : $$LocaleString:"Auto Repeat Columns"

    [Line: My AutoColumns]

		Fields      : Medium Prompt, My SelectAuto, My AutoColumns, My CollName, My StartPeriod, My EndPeriod, My SetPeriodicity
        Local       : Field : Medium Prompt 	: Info 		: $$LocaleString:"Repeat Using :"
        SpaceBottom : 0.25

        [Field: My SelectAuto]

            Use         : Short Name Field
            Table       : MyAutoColumns1
            Show Table  : Always

        [Field: My AutoColumns]

			Use			: Short Name Field
			Invisible   : Yes
            Set as      : $$Table:MySelectAuto:$VarName
            Set always  : Yes
			Skip        : Yes
			


;; Function Table selects the Object Name from the previous Field MySelectAuto
;; and displays the corresponding method value of VarName

        [Field: My CollName]

			Use			: Short Name Field
			Invisible   : Yes
            Set as      : $$Table:MySelectAuto:$CollName
			Modifies    : DSPRepeatCollection
            Set always  : Yes
			Skip        : Yes

;; We are modifying the value of the default variable DSPRepeatCollection
;; by the value of the Method CollName from the selected Object
;; DSPRepeatCollection is repeated in the Default Variables SVCurrentCompany,
;; SVFromDate and SVToDate, which gets new values for each column

        [Field: My StartPeriod]

            Use         : Short Date Field
			Invisible   : Yes
            Set as      : if $$IsEmpty:$$Table:MySelectAuto:$Periodicity then ##SVFromDate else +
                          if $$Table:MySelectAuto:$Periodicity = "Day" then ##SVFromDate else +
                          $$LowValue:SVFromDate
            Set always  : Yes
			Modifies    : SVFromDate
			Skip        : Yes

;; Value of Variable SVFromDate is set here based on the Periodicity Method.
;; LowValue is a Function that returns beginning date of the Current Period

        [Field: My EndPeriod]

            Use         : Short Date Field
			Invisible   : Yes
            Set as      : if $$IsEmpty:$$Table:MySelectAuto:$Periodicity then ##SVToDate else +
                          if $$Table:MySelectAuto:$Periodicity = "Day" then $$MonthEnd:#DSPStartPeriod else $$HighValue:SVToDate
            Set always  : Yes
			Modifies    : SVToDate
			Skip        : Yes

;; Value of Variable SVToDate is set here based on the Periodicity Method.
;; MonthEnd is a Function gives the last day for a given month

        [Field: My SetPeriodicity]

            Use         : Short Name Field
			Invisible   : Yes
            Set as      : if NOT $$IsEmpty:$$Table:MySelectAuto:$Periodicity then $$Table:MySelectAuto:$Periodicity else "Month"
            Set always  : Yes
			Modifies    : SVPeriodicity

             
                                        
;; End-of-File
